package de.seminar.lego3D;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;

/**
 * Class representing a lego brick as object, contatining all necessary information.
 * @author Christian Lander
 *
 */
public class Legobrick {
	
	/** index of the lego brick **/
	private int index;
	
	/** color of the brick **/
	public int color;
	
	/** icon of the lego brick **/
	private ImageView icon;
	private Drawable drawableIcon;
	
	/** array containing information about the habit of the brick 
	 *  example: a lego brick that has a L-Form is represented by 2-1-1**/
	private int[] brickLayout;
	
	/**
	 * Separator for the messages
	 */
	private final String seperator = "#";
	
	/**
	 * Creates a Lego brick with the given parameters.
	 * @param idx - index of the image
	 * @param ctx - the context of the activity
	 * @param layout - the layout of the brick
	 */
	public Legobrick(int idx, Context ctx, int ... layout) {
		this.brickLayout = layout;
		
		index = idx;
		
		icon = new ImageView(ctx);
		drawableIcon = ctx.getResources().getDrawable(index);
		icon.setImageDrawable(drawableIcon);
	}
	
	/**
	 * empty constructor
	 */
	public Legobrick() {
		
	}

	/**
	 * Sets the layout to the given one.
	 * @param layout to set
	 */
	public void setLayout(int ... layout) {
		this.brickLayout = layout;
	}
	
	/**
	 * Returns the layout of the brick as array.
	 * @return
	 */
	public int[] getLayout() {
		return this.brickLayout;
	}

	/**
	 * Sets the color to the given one.
	 * @param color to set
	 */
	public void setColor(int color) {
		this.color = color;
	}

	/**
	 * Returns the icon of this Lego brick.
	 * @return
	 */
	public View getIcon() {
		return icon;
	}
	
	/**
	 * Returns the icon as drawable.
	 * @return
	 */
	public Drawable getDrawableIcon() {
		return drawableIcon;
	}
	
	/**
	 * Returns a representation of the layout array as string.
	 * @return
	 */
	public String layoutToString() {
		String res = "";
		for (int i : brickLayout) {
			res += i + seperator;
		}
		return res;
	}
}
